#!/bin/bash
# filename: floating_boot.sh
# description: for i3wm, when I open a window it boot as full tab of something like tab window
#              but I want it to be floating window as I can see small size
# requirements: i3-msg jq programs


# Start your application in the background
./a.out &
APP_PID=$!

# Wait for the window to appear and get its ID
while true; do
    # Get the window ID using i3's JSON tree and jq filtering
    WINDOW_ID=$(i3-msg -t get_tree | jq -r '.. | objects | select(.name == "dmenu") | .id')
    
    if [[ -n "$WINDOW_ID" ]]; then
        # Apply floating and resize commands
        i3-msg "[con_id=$WINDOW_ID] floating enable"
        i3-msg "[con_id=$WINDOW_ID] resize set 400 500"
        break
    fi
    
    sleep 0.1  # Check every 100ms
done

# Wait for the application to exit
wait $APP_PID